package edu.thu.thss.yxy.gui.custom;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;


public class MyButton extends JButton{
	private Image bgImage;

	private Image bgRolloverImage;

	private Image iconImage;
	
	public MyButton(Image bgImage, Image rolloverImage, Image iconImage) {
		super();

		this.iconImage = iconImage;
		this.bgImage = bgImage;
		this.bgRolloverImage = rolloverImage;

		this.setPreferredSize(new Dimension(this.bgImage.getWidth(null),
				this.bgImage.getHeight(null)));

		this.setIcon(new ImageIcon(this.bgImage));
	}

	public void paint(Graphics g) {

		g.drawImage(this.bgImage, 0, 0, this);

		if (this.iconImage != null) {

			g.drawImage(this.iconImage,
							(this.bgImage.getWidth(null) - 
							this.iconImage.getWidth(null)) / 2,
							(this.bgImage.getHeight(null) - 
							this.iconImage.getHeight(null)) / 2, this);
		}

		if (this.getModel().isRollover()) {

			g.setColor(new Color(154, 154,	154));
			g.drawImage(this.bgRolloverImage, 0, 0, this);

			if (this.iconImage != null) {

				g.drawImage(this.iconImage,
								(this.bgImage.getWidth(null) - 
								this.iconImage.getWidth(null)) / 2, 
								(this.bgImage.getHeight(null) - 
								this.iconImage.getHeight(null)) / 2, this);
			}
		}
	}

	public Image getBgImage() {
		return bgImage;
	}

	public void setBgImage(Image bgImage) {
		this.bgImage = bgImage;
	}

	public Image getBgRolloverImage() {
		return bgRolloverImage;
	}

	public void setBgRolloverImage(Image bgRolloverImage) {
		this.bgRolloverImage = bgRolloverImage;
	}

	public Image getIconImage() {
		return iconImage;
	}

	public void setIconImage(Image iconImage) {
		this.iconImage = iconImage;
	}
}
